package Tools.Drawing;

import java.util.*;
import java.util.Map.Entry;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.geom.Vector2f;

// TODO: comments
// TODO: test

/** SpriteFont class
 * @author Aikidos
 */
public class SpriteFont {
	
	private Map<String, Image> _alphabet = new HashMap<String, Image>();
	private int _offset = 3;
	private float _alpha = 1f;

	public float getAlpha() {
		return _alpha;
	}
	
	public void setOffset(int offset) {
		_offset = offset;
	}
	
	public void setAlpha(float alpha) {
		_alpha = alpha;
		
		for (Entry<String, Image> entry : _alphabet.entrySet()) {
			entry.getValue().setAlpha(alpha);
		}
	}
	
	public void addLetter(String letter, Image img) {
		if (!_alphabet.containsKey(letter)) {
			_alphabet.put(letter, img);
		}
	}
	
	public void drawText(Graphics g, String text, Vector2f drawPos) {
		Vector2f currPos = new Vector2f(drawPos);
		
		for (int i = 0; i < text.length(); i++) {
			String letter = Character.toString(text.charAt(i));
			if (_alphabet.containsKey(letter)) {
				_alphabet.get(letter).draw(currPos.x, currPos.y);
				currPos.x += _alphabet.get(letter).getWidth() + _offset;
			}
		}
	}
	
}
